using System;
using System.Runtime.Serialization;
using MiniStock.Entities.Common;
using MiniStock.Entities.Common.Events;

namespace MiniStock.Entities.Stock.Events.Order
{
    [DataContract]
    [KnownType(typeof(CreateOrderEvent))]
    [KnownType(typeof(ChangeOrderAmountEvent))]
    [KnownType(typeof(ChangeOrderDeadlineEvent))]
    [KnownType(typeof(ChangeOrderProductEvent))]
    [KnownType(typeof(SetOrderShippedEvent))]
    public abstract class OrderEventBase : EntityEventBase
    {
        [DataMember]
        public Guid Id { get; set; }

        public override void ApplyTo(EntityBase entity)
        {
            if (entity != null && !(entity is Stock.Order))
                throw new ApplicationException("Event is only valid for orders");
        }

        public override bool IsConstructionMessage
        {
            get { return this is CreateOrderEvent; }
        }

        public override string GetEntityHash()
        {
            return "Order|" + Id;
        }

        public override Type GetEntityType()
        {
            return typeof(Stock.Order);
        }
    }
}